i = 0
rf.results <- list()
for (year in start.year:end.year) {
  i = i + 1
  print(year)
  # Generate dependent variable
  # Fit Random Forest
  set.seed(i*123)
  rf.results[[i]] <- randomForest(x = as.matrix(dta[dta[,t.var]< year,
                                                         rhs]),
                           y = as.matrix(dta[dta[,t.var]< year,
                                                  dv]),
                           ntree = rf_count_params$ntree, 
                           nodesize = rf_count_params$nodesize, 
                           type = rf_count_params$type,
                           do.trace = rf_count_params$do.trace
  )
  rf.results[[i]]$fit.oos <- predict(rf.results[[i]],
                                        newdata = as.matrix(dta[dta[,t.var] == year,
                                                                  rhs]),
                                     type = "response")
  rf.results[[i]]$actual.oos <- as.matrix(dta[dta[,t.var]== year,
                                                   dv])
  # Display time
  hours <- floor((proc.time()[3]-start.time)/3600)
  mins <- floor((proc.time()[3]-start.time)/60) - hours*60
  secs <- floor((proc.time()[3]-start.time)) - hours*3600 - mins*60
  
  print(paste(hours,
              "h",
              mins,
              "m",
              secs,
              "s elapsed",
              sep = ""))
}
save(rf.results,
     file=paste(modeldir,"/",
                country,
                "_rf_",
                "count",
                "_",
                rhs.group,fileext,
                ".RData",
                sep = ""))